suppressPackageStartupMessages(library(tidyverse))
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
devtools::load_all('~/Google Drive/My Drive/Scripts/R_packages/myUtilities/')
## ℹ Loading myUtilities
wd <- "/Users/s-mitsutomi/My Drive (shuheimitsutomi@ric.u-tokyo.ac.jp)/Analysis/METTL2A/"
setwd(wd)

tabledir <- paste0(wd, 'Tables/DRS_m3C_sites/Gprofiler/')
figdir  <- paste0(wd, 'Figures/DRS_m3C_sites/Gprofiler/')

num_sites_in_transcripts <- 
  read_tsv(
    paste0(wd, 'Tables/DRS/Positions/common_sig_seqs_in_intensity_up_2024-04-10.tsv.gz')
  )
## Rows: 605 Columns: 65
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (30): transcript_id, transcript_name, ref_kmer, GMM_cov_type_G, cluster_...
## dbl (35): position, GMM_logit_pvalue_G, KS_dwell_pvalue_G, KS_intensity_pval...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
num_sites_in_transcripts
## # A tibble: 605 × 65
##    transcript_id     transcript_name position ref_kmer GMM_logit_pvalue_G
##    <chr>             <chr>              <dbl> <chr>                 <dbl>
##  1 ENST00000429711.7 RPL32-204            422 GCCCA                 1    
##  2 ENST00000647248.2 RPL35A-211           380 ACCCC                 1    
##  3 ENST00000647248.2 RPL35A-211           381 CCCCT                 1    
##  4 ENST00000389680.2 MT-RNR1-201           43 ACACA                 1    
##  5 ENST00000389680.2 MT-RNR1-201           57 CCCCG                 1    
##  6 ENST00000389680.2 MT-RNR1-201           71 GTTCA                 1    
##  7 ENST00000389680.2 MT-RNR1-201           73 TCACC                 1    
##  8 ENST00000389680.2 MT-RNR1-201           75 ACCCT                 0.777
##  9 ENST00000389680.2 MT-RNR1-201           93 ATCAA                 1    
## 10 ENST00000389680.2 MT-RNR1-201          138 GCTTA                 1    
## # ℹ 595 more rows
## # ℹ 60 more variables: KS_dwell_pvalue_G <dbl>, KS_intensity_pvalue_G <dbl>,
## #   GMM_cov_type_G <chr>, GMM_n_clust_G <dbl>, cluster_counts_G <chr>,
## #   Logit_LOR_G <dbl>, c1_mean_intensity_G <dbl>, c2_mean_intensity_G <dbl>,
## #   c1_median_intensity_G <dbl>, c2_median_intensity_G <dbl>,
## #   c1_sd_intensity_G <dbl>, c2_sd_intensity_G <dbl>, c1_mean_dwell_G <dbl>,
## #   c2_mean_dwell_G <dbl>, c1_median_dwell_G <dbl>, c2_median_dwell_G <dbl>, …
gprofiler_gost <- function() {
  
  gostres <-
    gprofiler2::gost(
      query = list(
        'methylated' = str_remove(
          num_sites_in_transcripts$transcript_id,
          '[.][0-9]+$')
      ),
      organism = 'hsapiens',
      ordered_query = TRUE,
      significant = TRUE,
      #multi_query = TRUE
    )
  gostres$result |>
    as_tibble()
  
}

simplify_terms <- function(df) {
  
  term_ranks <-
    df |>
    arrange(p_value) |>
    select(rank, query, term_id) |>
    rename(
      parent_term_rank = rank, parent_term_id = term_id
    )
  
  df |>
    arrange(p_value) |>
    select(rank, query, signed_log10p, source, term_name,
           term_id, source_order, parents) |>
    unnest_longer(col = parents) |>
    rename(parent_term_id = parents) |>
    left_join(term_ranks) |>
    filter(is.na(parent_term_rank) | rank < parent_term_rank) |>
    select(-starts_with('parent_')) |>
    distinct()
  
}

dual_barplot_theme <- function() {
  
  theme_classic(base_size = 7) +
    theme(
      axis.title.y = element_blank(),
      axis.text.y  = element_blank(),
      axis.line.y  = element_blank(),
      axis.ticks.y = element_blank()
    )
  
}


gprofiler_result <-
  gprofiler_gost() |>
  mutate(
    signed_log10p = -log10(p_value)
  ) |>
  arrange(p_value)
gprofiler_result
## # A tibble: 576 × 15
##    query   significant  p_value term_size query_size intersection_size precision
##    <chr>   <lgl>          <dbl>     <int>      <int>             <int>     <dbl>
##  1 methyl… TRUE        1.65e-49       117         76                31     0.408
##  2 methyl… TRUE        5.94e-44        90         76                31     0.408
##  3 methyl… TRUE        2.99e-43        94         76                31     0.408
##  4 methyl… TRUE        4.05e-42       192         76                31     0.408
##  5 methyl… TRUE        7.14e-42        90         76                30     0.395
##  6 methyl… TRUE        1.26e-41       156         76                30     0.395
##  7 methyl… TRUE        3.37e-41        94         76                30     0.395
##  8 methyl… TRUE        3.37e-41        94         76                30     0.395
##  9 methyl… TRUE        7.11e-41        96         76                30     0.395
## 10 methyl… TRUE        5.98e-40       102         76                30     0.395
## # ℹ 566 more rows
## # ℹ 8 more variables: recall <dbl>, term_id <chr>, source <chr>,
## #   term_name <chr>, effective_domain_size <int>, source_order <int>,
## #   parents <list>, signed_log10p <dbl>
gprofiler_result_GOBP_simplified <-
  gprofiler_result |>
  filter(source == 'GO:BP') |>
  rownames_to_column(var = 'rank') |>
  simplify_terms()
## Joining with `by = join_by(query, parent_term_id)`
gprofiler_result_GOBP_simplified
## # A tibble: 66 × 7
##    rank  query      signed_log10p source term_name          term_id source_order
##    <chr> <chr>              <dbl> <chr>  <chr>              <chr>          <int>
##  1 1     methylated          40.9 GO:BP  cytoplasmic trans… GO:000…          736
##  2 2     methylated          25.8 GO:BP  translation        GO:000…         2194
##  3 3     methylated          25.3 GO:BP  peptide biosynthe… GO:004…        10843
##  4 4     methylated          23.0 GO:BP  amide biosyntheti… GO:004…        11153
##  5 5     methylated          22.6 GO:BP  peptide metabolic… GO:000…         2266
##  6 6     methylated          22.6 GO:BP  organonitrogen co… GO:190…        22100
##  7 7     methylated          20.1 GO:BP  amide metabolic p… GO:004…        11152
##  8 10    methylated          12.0 GO:BP  mitochondrial ATP… GO:004…        10709
##  9 11    methylated          12.0 GO:BP  ATP synthesis cou… GO:004…        10707
## 10 12    methylated          11.8 GO:BP  aerobic respirati… GO:000…         3273
## # ℹ 56 more rows
methylated_genes_GOBP_barplot <-
  gprofiler_result_GOBP_simplified  |>
  select(query, signed_log10p, term_name, source) |>
  filter(source == 'GO:BP') |>
  head(10) |>
  ggplot(aes(x = reorder(term_name, signed_log10p),
             y = signed_log10p, label = term_name)) +
  geom_bar(stat = 'identity', fill = 'grey20', alpha = .2) +
  geom_text(hjust = 0, colour = 'black', y = 0.2, size = 2.5) +
  coord_flip() +
  dual_barplot_theme()
ggsave(
  plot = methylated_genes_GOBP_barplot,
  filename = paste0(
    wd, 'Figures/DRS_m3C_sites/Gprofiler/2024-04-15_methylated_genes_GOBP_barplot.pdf'
  ),
  width = 4, height = 6, units = 'cm'
)

gprofiler_result_GOBP_simplified  |>
  #select(query, signed_log10p, term_name, source) |>
  filter(source == 'GO:BP') |>
  head(10) |> 
  ggplot(aes(
    x = reorder(term_name, signed_log10p),
    y = 'query',
    fill = signed_log10p
  )) +
  geom_tile() +
  coord_flip() +
  scale_fill_gradient(limits = c(0, 100), low = 'gray', high = 'red') +
  theme_minimal()

for (gp_source in unique(gprofiler_result$source)) {
  
  filtered_resuls <- 
    gprofiler_result |>
    filter(source == gp_source) |>
    select(query, p_value, term_name, source) |>
    head(20) 
  
  filtered_resuls |>
    print()
  
  plot_bar <- 
    filtered_resuls |> 
    ggplot(aes(
      x = reorder(term_name, -p_value),
      y = p_value |> log10())) +
    geom_bar(stat = 'identity') +
    labs(title = gp_source) +
    coord_flip()
  print(plot_bar)
  
}
## # A tibble: 20 × 4
##    query       p_value term_name                                    source
##    <chr>         <dbl> <chr>                                        <chr> 
##  1 methylated 1.65e-49 cytosolic ribosome                           GO:CC 
##  2 methylated 4.05e-42 ribosomal subunit                            GO:CC 
##  3 methylated 2.72e-31 ribosome                                     GO:CC 
##  4 methylated 7.75e-30 cytosolic large ribosomal subunit            GO:CC 
##  5 methylated 1.79e-25 large ribosomal subunit                      GO:CC 
##  6 methylated 6.12e-18 cytosolic small ribosomal subunit            GO:CC 
##  7 methylated 2.03e-16 small ribosomal subunit                      GO:CC 
##  8 methylated 5.16e-16 focal adhesion                               GO:CC 
##  9 methylated 8.15e-16 cell-substrate junction                      GO:CC 
## 10 methylated 2.73e-14 inner mitochondrial membrane protein complex GO:CC 
## 11 methylated 6.01e-14 cytosol                                      GO:CC 
## 12 methylated 6.11e-14 respiratory chain complex                    GO:CC 
## 13 methylated 7.78e-14 extracellular exosome                        GO:CC 
## 14 methylated 7.96e-14 mitochondrial respirasome                    GO:CC 
## 15 methylated 1.11e-13 extracellular vesicle                        GO:CC 
## 16 methylated 1.12e-13 extracellular organelle                      GO:CC 
## 17 methylated 1.12e-13 extracellular membrane-bounded organelle     GO:CC 
## 18 methylated 1.54e-13 respirasome                                  GO:CC 
## 19 methylated 5.08e-12 cytoplasm                                    GO:CC 
## 20 methylated 8.78e-12 anchoring junction                           GO:CC

## # A tibble: 20 × 4
##    query       p_value term_name                                          source
##    <chr>         <dbl> <chr>                                              <chr> 
##  1 methylated 5.94e-44 Peptide chain elongation                           REAC  
##  2 methylated 2.99e-43 Eukaryotic Translation Elongation                  REAC  
##  3 methylated 7.14e-42 Viral mRNA Translation                             REAC  
##  4 methylated 3.37e-41 Selenocysteine synthesis                           REAC  
##  5 methylated 3.37e-41 Eukaryotic Translation Termination                 REAC  
##  6 methylated 7.11e-41 Nonsense Mediated Decay (NMD) independent of the … REAC  
##  7 methylated 5.98e-40 Response of EIF2AK4 (GCN2) to amino acid deficien… REAC  
##  8 methylated 5.98e-40 Formation of a pool of free 40S subunits           REAC  
##  9 methylated 1.52e-38 L13a-mediated translational silencing of Cerulopl… REAC  
## 10 methylated 2.06e-38 SRP-dependent cotranslational protein targeting t… REAC  
## 11 methylated 2.06e-38 GTP hydrolysis and joining of the 60S ribosomal s… REAC  
## 12 methylated 5.03e-38 Nonsense Mediated Decay (NMD) enhanced by the Exo… REAC  
## 13 methylated 5.03e-38 Nonsense-Mediated Decay (NMD)                      REAC  
## 14 methylated 6.74e-38 Selenoamino acid metabolism                        REAC  
## 15 methylated 1.59e-37 Cap-dependent Translation Initiation               REAC  
## 16 methylated 1.59e-37 Eukaryotic Translation Initiation                  REAC  
## 17 methylated 5.02e-36 Influenza Viral RNA Transcription and Replication  REAC  
## 18 methylated 4.10e-34 Influenza Infection                                REAC  
## 19 methylated 1.18e-33 Cellular response to starvation                    REAC  
## 20 methylated 1.87e-32 Regulation of expression of SLITs and ROBOs        REAC

## # A tibble: 20 × 4
##    query       p_value term_name                                          source
##    <chr>         <dbl> <chr>                                              <chr> 
##  1 methylated 1.26e-41 cytoplasmic translation                            GO:BP 
##  2 methylated 1.41e-26 translation                                        GO:BP 
##  3 methylated 5.06e-26 peptide biosynthetic process                       GO:BP 
##  4 methylated 1.03e-23 amide biosynthetic process                         GO:BP 
##  5 methylated 2.43e-23 peptide metabolic process                          GO:BP 
##  6 methylated 2.77e-23 organonitrogen compound biosynthetic process       GO:BP 
##  7 methylated 8.05e-21 amide metabolic process                            GO:BP 
##  8 methylated 1.02e-13 oxidative phosphorylation                          GO:BP 
##  9 methylated 5.55e-13 aerobic electron transport chain                   GO:BP 
## 10 methylated 1.11e-12 mitochondrial ATP synthesis coupled electron tran… GO:BP 
## 11 methylated 1.11e-12 ATP synthesis coupled electron transport           GO:BP 
## 12 methylated 1.63e-12 aerobic respiration                                GO:BP 
## 13 methylated 5.70e-12 respiratory electron transport chain               GO:BP 
## 14 methylated 1.20e-11 cellular respiration                               GO:BP 
## 15 methylated 1.08e-10 electron transport chain                           GO:BP 
## 16 methylated 2.13e-10 energy derivation by oxidation of organic compoun… GO:BP 
## 17 methylated 3.19e-10 cellular nitrogen compound biosynthetic process    GO:BP 
## 18 methylated 1.01e- 9 ribosome biogenesis                                GO:BP 
## 19 methylated 1.29e- 9 organonitrogen compound metabolic process          GO:BP 
## 20 methylated 3.92e- 9 generation of precursor metabolites and energy     GO:BP

## # A tibble: 8 × 4
##   query       p_value term_name                                           source
##   <chr>         <dbl> <chr>                                               <chr> 
## 1 methylated 3.54e-39 Cytoplasmic ribosomal proteins                      WP    
## 2 methylated 1.66e-12 Electron transport chain OXPHOS system in mitochon… WP    
## 3 methylated 3.31e- 6 Oxidative phosphorylation                           WP    
## 4 methylated 5.44e- 5 Mitochondrial complex IV assembly                   WP    
## 5 methylated 8.34e- 3 Nonalcoholic fatty liver disease                    WP    
## 6 methylated 1.01e- 2 Neuroinflammation                                   WP    
## 7 methylated 1.28e- 2 Mitochondrial complex I assembly model OXPHOS syst… WP    
## 8 methylated 1.52e- 2 5q35 copy number variation                          WP

## # A tibble: 16 × 4
##    query       p_value term_name                                         source
##    <chr>         <dbl> <chr>                                             <chr> 
##  1 methylated 1.31e-31 Ribosome                                          KEGG  
##  2 methylated 5.88e-26 Coronavirus disease - COVID-19                    KEGG  
##  3 methylated 7.05e-12 Oxidative phosphorylation                         KEGG  
##  4 methylated 1.40e-10 Diabetic cardiomyopathy                           KEGG  
##  5 methylated 6.77e-10 Chemical carcinogenesis - reactive oxygen species KEGG  
##  6 methylated 1.05e- 9 Thermogenesis                                     KEGG  
##  7 methylated 3.49e- 9 Parkinson disease                                 KEGG  
##  8 methylated 4.26e- 9 Prion disease                                     KEGG  
##  9 methylated 1.23e- 8 Huntington disease                                KEGG  
## 10 methylated 5.82e- 8 Amyotrophic lateral sclerosis                     KEGG  
## 11 methylated 7.79e- 8 Alzheimer disease                                 KEGG  
## 12 methylated 6.19e- 7 Pathways of neurodegeneration - multiple diseases KEGG  
## 13 methylated 1.42e- 4 Cardiac muscle contraction                        KEGG  
## 14 methylated 1.47e- 3 Metabolic pathways                                KEGG  
## 15 methylated 3.82e- 3 Non-alcoholic fatty liver disease                 KEGG  
## 16 methylated 4.54e- 3 Retrograde endocannabinoid signaling              KEGG

## # A tibble: 20 × 4
##    query       p_value term_name                                          source
##    <chr>         <dbl> <chr>                                              <chr> 
##  1 methylated 9.69e-29 structural constituent of ribosome                 GO:MF 
##  2 methylated 3.56e-23 structural molecule activity                       GO:MF 
##  3 methylated 1.47e-14 oxidoreduction-driven active transmembrane transp… GO:MF 
##  4 methylated 1.49e-12 electron transfer activity                         GO:MF 
##  5 methylated 2.99e-11 primary active transmembrane transporter activity  GO:MF 
##  6 methylated 1.90e- 9 RNA binding                                        GO:MF 
##  7 methylated 9.51e- 8 active transmembrane transporter activity          GO:MF 
##  8 methylated 1.86e- 7 oxidoreductase activity                            GO:MF 
##  9 methylated 4.67e- 6 transmembrane transporter activity                 GO:MF 
## 10 methylated 6.12e- 6 NADH dehydrogenase (ubiquinone) activity           GO:MF 
## 11 methylated 6.76e- 6 NADH dehydrogenase (quinone) activity              GO:MF 
## 12 methylated 7.61e- 6 oxidoreductase activity, acting on a heme group o… GO:MF 
## 13 methylated 7.61e- 6 cytochrome-c oxidase activity                      GO:MF 
## 14 methylated 8.19e- 6 NADH dehydrogenase activity                        GO:MF 
## 15 methylated 8.99e- 6 NAD(P)H dehydrogenase (quinone) activity           GO:MF 
## 16 methylated 1.07e- 5 transporter activity                               GO:MF 
## 17 methylated 1.94e- 5 proton transmembrane transporter activity          GO:MF 
## 18 methylated 2.37e- 5 oxidoreductase activity, acting on NAD(P)H, quino… GO:MF 
## 19 methylated 3.02e- 5 rRNA binding                                       GO:MF 
## 20 methylated 1.39e- 4 oxidoreductase activity, acting on NAD(P)H         GO:MF

## # A tibble: 11 × 4
##    query       p_value term_name                                          source
##    <chr>         <dbl> <chr>                                              <chr> 
##  1 methylated 3.79e-22 Ribosome, cytoplasmic                              CORUM 
##  2 methylated 6.17e-15 Nop56p-associated pre-rRNA complex                 CORUM 
##  3 methylated 3.16e-13 60S ribosomal subunit, cytoplasmic                 CORUM 
##  4 methylated 1.56e- 7 40S ribosomal subunit, cytoplasmic                 CORUM 
##  5 methylated 5.69e- 7 40S ribosomal subunit, cytoplasmic                 CORUM 
##  6 methylated 2.14e- 5 Respiratory chain complex I (incomplete intermedi… CORUM 
##  7 methylated 3.73e- 4 TRBP containing complex (DICER, RPL7A, EIF6, MOV1… CORUM 
##  8 methylated 1.51e- 3 Respiratory chain complex I (gamma subunit) mitoc… CORUM 
##  9 methylated 1.59e- 3 Cytochrome c oxidase, mitochondrial                CORUM 
## 10 methylated 2.10e- 2 Ecsit complex (ECSIT, MT-CO2, NDUFA1, MT-ND1, TRA… CORUM 
## 11 methylated 3.16e- 2 Ferritin complex                                   CORUM

## # A tibble: 20 × 4
##    query       p_value term_name                                          source
##    <chr>         <dbl> <chr>                                              <chr> 
##  1 methylated 5.46e-15 Mitochondrial inheritance                          HP    
##  2 methylated 5.15e-13 Centrocecal scotoma                                HP    
##  3 methylated 1.79e-12 Ventricular preexcitation                          HP    
##  4 methylated 1.83e-12 Episodic vomiting                                  HP    
##  5 methylated 2.64e-12 Ragged-red muscle fibers                           HP    
##  6 methylated 2.64e-12 Mitochondrial myopathy                             HP    
##  7 methylated 1.10e-11 Abnormal mitochondria in muscle tissue             HP    
##  8 methylated 2.31e-11 Mitochondrial respiratory chain defects            HP    
##  9 methylated 3.91e-11 Leber optic atrophy                                HP    
## 10 methylated 1.59e-10 Muscle abnormality related to mitochondrial dysfu… HP    
## 11 methylated 1.72e-10 Central retinal vessel vascular tortuosity         HP    
## 12 methylated 1.72e-10 Retinal arterial tortuosity                        HP    
## 13 methylated 2.62e-10 Retinal telangiectasia                             HP    
## 14 methylated 1.57e- 9 Slow decrease in visual acuity                     HP    
## 15 methylated 9.95e- 9 Stroke-like episode                                HP    
## 16 methylated 1.11e- 8 Blurred vision                                     HP    
## 17 methylated 1.44e- 8 Proximal tubulopathy                               HP    
## 18 methylated 1.58e- 8 Sensorimotor neuropathy                            HP    
## 19 methylated 1.66e- 8 Mixed demyelinating and axonal polyneuropathy      HP    
## 20 methylated 1.66e- 8 Multiple glomerular cysts                          HP

## # A tibble: 17 × 4
##    query          p_value term_name       source
##    <chr>            <dbl> <chr>           <chr> 
##  1 methylated 0.000000303 hsa-miR-320a    MIRNA 
##  2 methylated 0.00000244  hsa-miR-652-3p  MIRNA 
##  3 methylated 0.0000284   hsa-miR-744-5p  MIRNA 
##  4 methylated 0.0000473   hsa-let-7c-5p   MIRNA 
##  5 methylated 0.0000718   hsa-miR-296-3p  MIRNA 
##  6 methylated 0.000140    hsa-let-7e-5p   MIRNA 
##  7 methylated 0.000260    hsa-let-7a-5p   MIRNA 
##  8 methylated 0.000357    hsa-miR-100-5p  MIRNA 
##  9 methylated 0.00108     hsa-miR-615-3p  MIRNA 
## 10 methylated 0.00316     hsa-miR-760     MIRNA 
## 11 methylated 0.00337     hsa-miR-186-5p  MIRNA 
## 12 methylated 0.00456     hsa-miR-1301-3p MIRNA 
## 13 methylated 0.0147      hsa-let-7b-5p   MIRNA 
## 14 methylated 0.0162      hsa-miR-16-5p   MIRNA 
## 15 methylated 0.0332      hsa-miR-99a-5p  MIRNA 
## 16 methylated 0.0360      hsa-miR-7150    MIRNA 
## 17 methylated 0.0454      hsa-miR-96-5p   MIRNA

## # A tibble: 20 × 4
##    query          p_value term_name                                       source
##    <chr>            <dbl> <chr>                                           <chr> 
##  1 methylated 0.000000572 Factor: GCMa:HOXB13; motif: RTGCGGGTMATAAAN     TF    
##  2 methylated 0.000141    Factor: GCMa:HOXA13; motif: RTGCGGGTAATAAA      TF    
##  3 methylated 0.000651    Factor: GCMa:HOXB13; motif: RTGCGGGTMATAAAN; m… TF    
##  4 methylated 0.000773    Factor: GCMb:Prrxl1; motif: ATRCGGGTNATTAN      TF    
##  5 methylated 0.00128     Factor: MYBL1; motif: ACCGTTAACSGY              TF    
##  6 methylated 0.00137     Factor: GCMb:FOXI1; motif: RTAAATANGGGNN        TF    
##  7 methylated 0.00207     Factor: E2F2; motif: AAAATGGCGCCATTTT           TF    
##  8 methylated 0.00232     Factor: Cdx-2; motif: NRTCGTAANNNN; match clas… TF    
##  9 methylated 0.00474     Factor: ZNF647; motif: NTAGGCCTAN; match class… TF    
## 10 methylated 0.00615     Factor: GCMa:HOXA2; motif: RTRNGGGYNTAATNN      TF    
## 11 methylated 0.00665     Factor: SAP-1; motif: NTCGTAAATGCN              TF    
## 12 methylated 0.00908     Factor: Barhl-1; motif: NTAAACGN; match class:… TF    
## 13 methylated 0.0108      Factor: ZNF286B; motif: NTTGGCGGATGM            TF    
## 14 methylated 0.0108      Factor: ZNF286; motif: NTTGGCGGATGM             TF    
## 15 methylated 0.0121      Factor: meis1:Elf-1; motif: NTGCCGGAAGTN; matc… TF    
## 16 methylated 0.0127      Factor: Oct-1; motif: NNNRTAATNANNN; match cla… TF    
## 17 methylated 0.0132      Factor: GCMa:HOXA2; motif: RTRNGGGYNTAATNN; ma… TF    
## 18 methylated 0.0142      Factor: PU.1; motif: ACTTCCTCT                  TF    
## 19 methylated 0.0224      Factor: HOXA5; motif: TGCNHNCWYCCYCATTAKTGNDCN… TF    
## 20 methylated 0.0243      Factor: PU.1; motif: NRAAAGAGGAAGTGARA          TF

## # A tibble: 20 × 4
##    query       p_value term_name                                source
##    <chr>         <dbl> <chr>                                    <chr> 
##  1 methylated 0.000466 duodenum; paneth cells[High]             HPA   
##  2 methylated 0.000816 appendix; goblet cells[High]             HPA   
##  3 methylated 0.00101  appendix; enterocytes[High]              HPA   
##  4 methylated 0.00115  duodenum; paneth cells[≥Medium]          HPA   
##  5 methylated 0.00193  small intestine; goblet cells[≥Medium]   HPA   
##  6 methylated 0.00196  colon; goblet cells[High]                HPA   
##  7 methylated 0.00237  duodenum; goblet cells[High]             HPA   
##  8 methylated 0.00255  duodenum; paneth cells[≥Low]             HPA   
##  9 methylated 0.00257  rectum; goblet cells[High]               HPA   
## 10 methylated 0.00310  colon; enterocytes[High]                 HPA   
## 11 methylated 0.00444  rectum; enterocytes[High]                HPA   
## 12 methylated 0.00467  pancreas; exocrine glandular cells[High] HPA   
## 13 methylated 0.00488  appendix; endocrine cells[≥Low]          HPA   
## 14 methylated 0.00507  appendix; endocrine cells[High]          HPA   
## 15 methylated 0.00528  appendix; goblet cells[≥Low]             HPA   
## 16 methylated 0.00557  duodenum; enterocytes[High]              HPA   
## 17 methylated 0.00608  appendix; enterocytes[≥Medium]           HPA   
## 18 methylated 0.00633  small intestine; goblet cells[High]      HPA   
## 19 methylated 0.00655  appendix; goblet cells[≥Medium]          HPA   
## 20 methylated 0.00670  skin 2; cells in basal layer[High]       HPA